// 鉴权示例代码
export let authentication = `package cn.publink.shb.application.facade.controller.connector.outside;

import cn.publink.shb.application.service.apicenter.ShbCodeAuth;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
/**
 * 代码鉴权说明
 * 1.入参map中包含在 系统集成-三方应用集成-应用鉴权 中配置的鉴权字段
 * map.key = 鉴权字段字段key
 * map.value = 账户中配置的对应内容
 *
 * 2.最后返回的数据鉴权结果 是一个json字符串
 * 3.可以通过@Autowired注入spring容器中的bean
 * 详细说明查看文档：https://www.yuque.com/shb/help2/ox8c8k8i3hp1g6do#N8WYr
 */
public class ShbCodeAuthDemo implements ShbCodeAuth {

  private final static Logger log = LoggerFactory.getLogger("ShbConvertDataDemo");

  @Override
  public String initiateAuth(Map<String, Object> map) {

    //例如通过http调用获取了token，这里自行构建对象，最后转为字符串即可
    String token = "xxx"; //表示获取到的token
    Map<String, String> resultMap = new HashMap<>();
    resultMap.put("token", token);
    return JSON.toJSONString(resultMap);
  }
}
`;

// 参数转换示例代码
export let convertData = `package cn.publink.shb.application.facade.controller.connector.outside;

import cn.publink.shb.application.service.common.service.ShbConvertDataService;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 执行参数转换的示例
 * 1.fromData为前置节点的业务数据，例如某工单表单数据，某客户表单数据
 * 数据结构为typeId:fieldName。例如某工单的类型typeId=bdf4d1c4-8d1f-458e-b4fc-24835499329e，fromData数据如下
 * {
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:taskNo": "TAQ125024030520",
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:customer": {
 *     "serialNumber": "zmjjkk",
 *     "name": "zmjjkk",
 *     "id": "9ea625a6-eb22-11ee-8999-00163f00409a"
 *   },
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:templateId": "bdf4d1c4-8d1f-458e-b4fc-24835499329e",
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:createTime": "2024-03-28 14:47:01"
 * }
 *
 * 2.最后返回的数据为转换后的结果，会直接作为参数调用当前节点配置的接口
 * 3.可以通过@Autowired注入spring容器中的bean
 * 详细说明查看文档：https://www.yuque.com/shb/help2/ox8c8k8i3hp1g6do#N8WYr
 */
public class ShbConvertDataDemo implements ShbConvertDataService {

  private final static Logger log = LoggerFactory.getLogger("ShbConvertDataDemo");

  @Override
  public JSONObject convertData(JSONObject fromData) {
    //Do something...
    JSONObject result = new JSONObject();
    //result.put("id", "test"); 自定义返回的数据
    return result;
  }
}
`;

// 执行代码示例代码
export let executeCode = `package cn.publink.shb.application.facade.controller.connector.outside;

import cn.publink.shb.application.service.common.service.ShbExecuteCodeService;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 执行代码的示例
 * 1.fromObject为前置节点的业务数据，例如某工单表单数据，某客户表单数据
 * 数据结构为typeId:fieldName。例如某工单的类型typeId=bdf4d1c4-8d1f-458e-b4fc-24835499329e，fromData数据如下
 * {
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:taskNo": "TAQ125024030520",
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:customer": {
 *     "serialNumber": "zmjjkk",
 *     "name": "zmjjkk",
 *     "id": "9ea625a6-eb22-11ee-8999-00163f00409a"
 *   },
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:templateId": "bdf4d1c4-8d1f-458e-b4fc-24835499329e",
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:createTime": "2024-03-28 14:47:01"
 * }
 *
 * 2.最后返回的JSONObject会作为参数流转到下个节点，后续节点可拿到JSONObject的数据,如果不需要返回数据，直接返回null即可
 * 3.可以通过@Autowired注入spring容器中的bean
 * 详细说明查看文档：https://www.yuque.com/shb/help2/ox8c8k8i3hp1g6do#N8WYr
 */
public class ShbExecuteCodeDemo implements ShbExecuteCodeService {

  private final static Logger log = LoggerFactory.getLogger("ShbExecuteCodeDemo");

  @Override
  public JSONObject execute(JSONObject fromObject) {
    //do something ,执行需要的逻辑
    return null;
  }
}
`;

// 条件判断示例代码
export let condition = `package cn.publink.shb.application.facade.controller.connector.outside;

import cn.publink.shb.application.service.common.service.ShbMatchRuleService;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 执行条件判断的示例
 * 1.fromData为前置节点的业务数据，例如某工单表单数据，某客户表单数据
 * 数据结构为typeId:fieldName。例如某工单的类型typeId=bdf4d1c4-8d1f-458e-b4fc-24835499329e，fromData数据如下
 * {
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:taskNo": "TAQ125024030520",
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:customer": {
 *     "serialNumber": "zmjjkk",
 *     "name": "zmjjkk",
 *     "id": "9ea625a6-eb22-11ee-8999-00163f00409a"
 *   },
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:templateId": "bdf4d1c4-8d1f-458e-b4fc-24835499329e",
 *   "bdf4d1c4-8d1f-458e-b4fc-24835499329e:createTime": "2024-03-28 14:47:01"
 * }
 *
 * 2.最后返回true/false 表示条件匹配或不匹配
 * 3.可以通过@Autowired注入spring容器中的bean
 * 详细说明查看文档：https://www.yuque.com/shb/help2/ox8c8k8i3hp1g6do#N8WYr
 */
public class ShbMatchRuleDemo implements ShbMatchRuleService {

  private final static Logger log = LoggerFactory.getLogger("ShbMatchRuleDemo");

  @Override
  public boolean match(JSONObject fromData) {
    //编写判断条件的代码
    return fromData.containsKey("bdf4d1c4-8d1f-458e-b4fc-24835499329e:taskNo");
  }
}
`;